package home.yadong.email;

import java.io.IOException;

import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.NoSuchProviderException;
import javax.mail.Store;
import javax.mail.search.FlagTerm;

public class EmailReceiver extends ImapEmailBase {
	private Store store;
	private Message[] messages;
	private Email[] emails;
	public EmailReceiver(String propertyFile) {
		super(propertyFile);
		try {
			store=this.session.getStore();
			store.connect(getIncomingHost(), getUser(), getPassword());
			Folder inbox = store.getFolder("Inbox");
			inbox.open(Folder.READ_WRITE);
			//get all the unread messages
			this.messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
			Multipart mp = null;
			for (Message msg : messages) {
				mp=(Multipart)msg.getContent();
			}
		} catch (NoSuchProviderException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public Store getStore() {
		return store;
	}
	public void setStore(Store store) {
		this.store = store;
	}
	public Message[] getMessages() {
		return messages;
	}
	public void setMessages(Message[] messages) {
		this.messages = messages;
	}
	public Email[] getEmails() {
		return emails;
	}
	public void setEmails(Email[] emails) {
		this.emails = emails;
	}
}
